package plantshop.view.listeners;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.io.Serializable;

import plantshop.view.PlayerMenu;

public class IPListener implements KeyListener,Serializable {
	private static final long serialVersionUID = -7031568619738355119L;
	String stringIP;
	PlayerMenu menu;
	
	public IPListener(PlayerMenu pane){
		this.menu = pane;
	}
	
	public String getIPAddress(){
		return stringIP;
	}

	@Override
	public void keyTyped(KeyEvent e) {
		if(e.getKeyChar() != KeyEvent.VK_BACK_SPACE){
			menu.addLetterToIP(e.getKeyChar());
		}
		menu.repaint();
	}

	@Override
	public void keyPressed(KeyEvent e) {
		switch(e.getKeyCode()){
		case KeyEvent.VK_ENTER:
			if(menu.getIPAddress() != "")
				menu.setNeedsIP(false);
			menu.checkIP();
			break;
		case KeyEvent.VK_BACK_SPACE:
			menu.removeLetterFromIP();
			break;
		}		
	}
	
	@Override
	public void keyReleased(KeyEvent e) {}
}
